home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: twisto.eng.hou.compaq.com!news
- From: Cindy McGee <cindym@bangate.compaq.com>
- Subject: Problem: Incorrect ifstream handling?
- Message-ID: <3172E386.28C@bangate.compaq.com>
- Sender: news@twisto.eng.hou.compaq.com (System Administrator)
- Mime-Version: 1.0
- X-Mailer: Mozilla 2.0 (Win95; I)
- Content-Type: text/plain; charset=us-ascii
- Organization: Compaq Computer Corporation
- Date: Tue, 16 Apr 1996 00:02:14 GMT
- X-Nntp-Posting-Host: 172.18.220.53
- Content-Transfer-Encoding: 7bit
-
- My reference material doesn't seem to clear on this subject.
-
- I'm using an input file stream to read data from a text file inside a
- MSVC++ 4.0 console application. The code actually compiles and runs
- normally, but with Bounds Checker for W95, I get several errors.
-
- Specifically, BC reports an "Invalid argument operator delete, HANDLE
- 0x01101350, Bad handle" in the streambuf destructor, a "Dynamic memory
- overrun 548 byte block allocated in malloc.c at line 160 HANDLE
- 0x01101330 Allocating thread ID... current thread ID...", another
- "invalid argument..." in the filebuf's scalar deleting destructor, and
- so on. Other, bigger objects have dynamic memory overruns that may be
- affected by this function.
-
- Without BC, I can run the app, but get strange behavior later with the
- bigger objects. For instance, inside
- TheApp->pOb->FooFoo(), iTheApp->pOb->m_iXxx is initialized, but
- this->m_iXxx is uninitialized and refuses to take an assignment.
-
- I seem to have either a memory allocation/de-allocation problem, faulty
- standard library classes, or a ifstream class handled incorrectly.
-
- Any ideas would be appreciated; I've included a code snippet below.
-
-
- Thanks!
-
- Cindy McGee
- --------------
- <cindym@bangate.compaq.com>
-
- ==============================================
- Given szFileName as "text.emu", my function performs the following:
-
- ifstream file(szFileName);
-
- if (!file)
- // ... error handling
- else
- {
- int iMax = 0;
- char sz[255];
-
- file >> iMax;
- file >> sz;
-
- for (int i = 0; i < iMax; i++)
- {
- if (0 == strcmp(sz,"<field1>"))
- {
- file.eatwhite()
- file.getline(sz,255);
- pObject->Setxxx(sz);
- file >> sz;
- }
-
- // ... many repeats of the above for different fields
- }
-
- // function returns
-